package com.itcam.tomcat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author : Cammy.Wu
 * Description :
 *
 * Servlet类中可以有service方法，用来饥饿收get或者post请求
 *                             如果service和doGet或者doPost同时存在，那么默认会调用service方法
 *                             如果同时有server，doGet，doPost，在service方法的实现中调用了super.service()会根据请求的方法跳转到doGet或者doPost方法
 * doGet方法：
 *             处理get请求
 * doPost方法：
 *             处理post请求
 *
 * 总结：
 *              在编写service类的时候，不需要重新实现service方法，只需要写doGet和doPost方法即可，用来接受post或get请求
 */

@WebServlet("/method")
public class MethodServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("post请求");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("get请求");
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("service");
    }
}
